package com.iawg.attrition.game.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;


import com.ardor3d.framework.FrameHandler;
import com.ardor3d.image.util.AWTImageLoader;
import com.ardor3d.util.Timer;
import com.iawg.attrition.engine.renderer.ArdorSWTRenderer;
import com.iawg.attrition.engine.renderer.AttritionScene;
import com.iawg.attrition.game.GameEngine;



public class SimpleCanvas{
	private Shell shell = null;
	private Composite contentPanel = null;
	private FrameHandler frameWork;
	private AttritionScene updater;

	public SimpleCanvas(){
		System.setProperty("ardor3d.useMultipleContexts", "true");
		Timer timer = new Timer();
		frameWork = new FrameHandler(timer);
		updater = new AttritionScene();
		frameWork.addUpdater(updater);
		AWTImageLoader.registerLoader();
	}

	/**
	 * This method initializes shell	
	 *
	 */
	public Shell getShell() {
		if(shell == null){
			shell = new Shell();
			shell.setLayout(new GridLayout());
			getContentPanel();
			shell.setSize(new Point(692, 401));
			shell.setText("Simple Test");
		}
		return shell;
	}

	/**
	 * This method initializes contentPanel	
	 * 	
	 * @return org.eclipse.swt.widgets.Composite	
	 */
	private Composite getContentPanel() {
		if (contentPanel == null) {
			GridData gridData = new GridData();
			gridData.horizontalAlignment = GridData.FILL;
			gridData.grabExcessHorizontalSpace = true;
			gridData.grabExcessVerticalSpace = true;
			gridData.verticalAlignment = GridData.FILL;
			contentPanel = new Composite(shell, SWT.NONE);
			contentPanel.setLayout(new GridLayout());
			contentPanel.setLayoutData(gridData);
			((ArdorSWTRenderer) GameEngine.ENGINE.getRenderer()).getArdorLWJGLCanvasRenderer(contentPanel, updater, frameWork);
			
		}
		return contentPanel;
	}
}